package ua.com.minus1.lookbattle;

import android.content.Context;
import com.google.gson.Gson;
import ua.com.minus1.lookbattle.models.Country;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Flash
 * Date: 17.08.12
 * Time: 17:08
 * To change this template use File | Settings | File Templates.
 */
public class CountriesFactory {

    public static List<Country> getCountries(Context context) {
        InputStream inputStream = context.getResources().openRawResource(R.raw.coutries_json);
        Gson gson = new Gson();
        CountryResult result = gson.fromJson(new InputStreamReader(inputStream), CountryResult.class);
        return result.countries;
    }

    public static Country getCountry(Context context, int id) {
        List<Country> countries = getCountries(context);
        return countries.get(id - 1);
    }

    public static Country getCountry(List<Country> countries, int id) {
        return countries.get(id - 1);
    }

    class CountryResult{
        public List<Country> countries;
    }

}
